$('#new_question').live("pageinit", function(event) {
	createNewQuestionPage();
});
$('#new_question').live("pagebeforeshow", function(event) {
	createNewQuestionPage();
});

function createNewQuestionPage() {
	new_question_title.value="";
	new_question_text.value="";
}

$('#new_question_form').submit(function(){
});


function postNewQuestion(){
	var course = JSON.parse(localStorage["course"]);
	
	var onderwerp
	if(new_question_title.value == "")
		onderwerp = "(geen onderwerp)";
	else
		onderwerp =new_question_title.value;

	var q = { "vakId":course.vakId, "subject":onderwerp, "text":new_question_text.value};
	console.log(JSON.stringify( q));
	var q1 = JSON.stringify(q);
	
	$.ajax( { 
		url: '/api/vraag/add',
		type: 'POST',	// Now we wait till we get response.
		data: q1,
		dataType:"json",
		contentType: 'application/json',
		success: function(data) { 	// ad the last 2 tweets to the page
				console.log("Gelukt!!");
		},
		error: function(data) { 	// ad the last 2 tweets to the page
			console.log("NIET Gelukt!!");
			console.log(data);
		}
		}
	);

	$.mobile.changePage('#course');		// load the page
}
function cancelNewQuestion(){
	new_question_title.value="";
	new_question_text.value="";
	
	$.mobile.changePage('#course');		// load the page
}